package com.suse.ecommerce.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class AdminInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session=request.getSession();
        Object teacher=session.getAttribute("store");
        String reqURL = request.getRequestURL().toString();
        String reqURI = request.getRequestURI();
        String servletPath = request.getServletPath();
        if(reqURI.indexOf("/admin_frame")!=-1 || reqURI.indexOf("/tgls") !=-1) {
            System.out.println(reqURI);
            System.out.println(teacher);
            if(teacher!=null) {
                return true;
            }else {
                return false;
            }
        }
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

    }
}
